package org.example.maven.controller;

import org.example.maven.annotation.ReadOnlyMode;
import org.example.maven.annotation.logAnnotation;
import org.example.maven.pojo.Result;
import org.example.maven.pojo.operation.loginLog.SearchLoginLog;
import org.example.maven.service.LoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RestController
@CrossOrigin
@RequestMapping("/loginLog")
public class loginLogController {
    @Autowired
    private LoginLogService loginLogService;
    @GetMapping
    @PreAuthorize("hasAnyAuthority('log:login')")
    //获取登录日志list显示信息
    public Result getLoginLog(@RequestParam("pageNum") Integer pageNum,@RequestParam("pageSize") Integer pageSize){
        Result result =Result.success();
        result.put("data",loginLogService.getLoginLog(pageNum,pageSize));
        result.put("total",loginLogService.getLoginLogCount(new SearchLoginLog()));
        System.out.println(loginLogService.getLoginLog(pageNum,pageSize));
        return result;
    }
    @DeleteMapping("/{ids}")
    @PreAuthorize("hasAnyAuthority('log:login')")
    //删除登录日志
    @ReadOnlyMode
    public Result deleteLoginLog(@PathVariable String[] ids){
        loginLogService.deleteLoginLog(ids);
        return Result.success("删除成功");
    }
    @GetMapping("/searchSpecieLoginLog")
    @PreAuthorize("hasAnyAuthority('log:login')")
    //获取特定的登录日志
    public Result getSpecieLoginLog(SearchLoginLog searchLoginLog,@RequestParam("pageNum")Integer pageNum,@RequestParam("pageSize")Integer pageSize){
        Result result=Result.success("查询成功");
        result.put("data",loginLogService.getSpecieLoginLog(searchLoginLog,pageNum,pageSize));
        System.out.println(searchLoginLog);
        result.put("total",loginLogService.getLoginLogCount(searchLoginLog));
        return result;
    }
    @DeleteMapping
    @ReadOnlyMode
    @PreAuthorize("hasAnyAuthority('log:login')")
    //删除全部登录日志
    public Result deleteLoginLogAll(){
        loginLogService.deleteLoginLogAll();
        return Result.success("清空成功");
    }
}
